package main

import "fmt"

func quickSort(data []int, l, r int) {
	if l >= r {
		return
	}

	beg := l
	end := r

	mid := data[l]

	for l < r {
		for r > l {
			if data[r] < mid {
				break
			}
			r--
		}

		if l != r {
			data[l] = data[r]
		}

		for l < r {
			if data[l] > mid {
				break
			}
			l++
		}

		if l != r {
			data[r] = data[l]
		}
	}

	data[l] = mid

	quickSort(data, beg, l-1)
	quickSort(data, l+1, end)
}
func sortArray(nums []int) []int {
	quickSort(nums, 0, len(nums)-1)
	return nums
}

func main() {
	arr := []int{5, 2, 3, 1}
	sortArray(arr)
	fmt.Println(arr)
}
